package com.hyh;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.HashMap;
import java.util.Map;

@RestController
public class SseMcpController {

//    @GetMapping(value = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
//    public SseEmitter handleSse() {
//        SseEmitter emitter = new SseEmitter(0L);
//
//        new Thread(() -> {
//            try {
//                ObjectMapper mapper = new ObjectMapper();
//
//                for (int i = 0; i < 5; i++) {
//                    Map<String, Object> jsonRpcMsg = new HashMap<>();
//                    jsonRpcMsg.put("jsonrpc", "2.0");
//                    jsonRpcMsg.put("method", "toolResponse");
//
//                    Map<String, String> params = new HashMap<>();
//                    params.put("content", "来自服务端的消息 #" + i);
//                    jsonRpcMsg.put("params", params);
//
//                    jsonRpcMsg.put("id", i);
//
//                    String json = mapper.writeValueAsString(jsonRpcMsg);
//
//                    emitter.send(SseEmitter.event()
//                            .name("message")
//                            .data(json));
//                    Thread.sleep(1000);
//                }
//                emitter.complete();
//            } catch (Exception e) {
//                emitter.completeWithError(e);
//            }
//        }).start();
//
//        return emitter;
//    }

}
